#!/usr/bin/env python
#coding:utf-8

import wx
import wx.xrc
import RTControl as RTC

###########################################################################
## Class ManualFrame
###########################################################################

class ManualFrame ( wx.Frame ):
    
    def __init__( self, parent ):
        self.condomain = app.condomain
        self.sensorcylinder = self.condomain.GetSensorCylinder()
        self.clampcylinder = self.condomain.GetClampCylinder()
        
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"手动操作", pos = wx.DefaultPosition, size = wx.Size( -1,-1 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
        
        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
        
        bSizer32 = wx.BoxSizer( wx.VERTICAL )
        
        self.m_panel20 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        bSizer33 = wx.BoxSizer( wx.VERTICAL )
        
        bSizer2 = wx.BoxSizer( wx.HORIZONTAL )
        
        self.m_bitmap1 = wx.StaticBitmap( self.m_panel20, wx.ID_ANY, wx.Bitmap( u"images/leaf.png", wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer2.Add( self.m_bitmap1, 0, wx.ALL, 5 )
        
        self.m_staticText1 = wx.StaticText( self.m_panel20, wx.ID_ANY, u"在这里进行手动操作", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText1.Wrap( -1 )
        self.m_staticText1.SetFont( wx.Font( 15, 70, 90, 92, False, wx.EmptyString ) )
        self.m_staticText1.SetForegroundColour( wx.Colour( 32, 141, 20 ) )
        
        bSizer2.Add( self.m_staticText1, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        bSizer33.Add( bSizer2, 0, wx.EXPAND, 5 )
        
        self.m_staticline1 = wx.StaticLine( self.m_panel20, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
        bSizer33.Add( self.m_staticline1, 0, wx.EXPAND |wx.ALL, 5 )
        
        bSizer37 = wx.BoxSizer( wx.HORIZONTAL )
        
        sbSizer5 = wx.StaticBoxSizer( wx.StaticBox( self.m_panel20, wx.ID_ANY, u"压紧气缸" ), wx.VERTICAL )
        
        self.m_btnClampStretch = wx.Button( self.m_panel20, wx.ID_ANY, u"伸出", wx.DefaultPosition, wx.Size( -1,50 ), 0 )
        sbSizer5.Add( self.m_btnClampStretch, 0, wx.ALL|wx.EXPAND, 5 )
        
        self.m_btnClampShrink = wx.Button( self.m_panel20, wx.ID_ANY, u"缩回", wx.DefaultPosition, wx.Size( -1,50 ), 0 )
        sbSizer5.Add( self.m_btnClampShrink, 0, wx.ALL|wx.EXPAND, 5 )
        
        self.m_btnClampStop = wx.Button( self.m_panel20, wx.ID_ANY, u"停止", wx.DefaultPosition, wx.Size( -1,50 ), 0 )
        sbSizer5.Add( self.m_btnClampStop, 0, wx.ALL|wx.EXPAND, 5 )
        
        bSizer37.Add( sbSizer5, 1, wx.EXPAND|wx.ALL, 5 )
        
        sbSizer3 = wx.StaticBoxSizer( wx.StaticBox( self.m_panel20, wx.ID_ANY, u"测量气缸" ), wx.VERTICAL )
        
        self.m_btnSensorStretch = wx.Button( self.m_panel20, wx.ID_ANY, u"伸出", wx.DefaultPosition, wx.Size( -1,50 ), 0 )
        sbSizer3.Add( self.m_btnSensorStretch, 0, wx.ALL|wx.EXPAND, 5 )
        
        self.m_btnSensorShrink = wx.Button( self.m_panel20, wx.ID_ANY, u"缩回", wx.DefaultPosition, wx.Size( -1,50 ), 0 )
        sbSizer3.Add( self.m_btnSensorShrink, 0, wx.ALL|wx.EXPAND, 5 )
        
        self.m_btnSensorStop = wx.Button( self.m_panel20, wx.ID_ANY, u"停止", wx.DefaultPosition, wx.Size( -1,50 ), 0 )
        sbSizer3.Add( self.m_btnSensorStop, 0, wx.ALL|wx.EXPAND, 5 )
        
        bSizer37.Add( sbSizer3, 1, wx.ALL|wx.EXPAND, 5 )
        
        bSizer33.Add( bSizer37, 1, wx.EXPAND, 5 )
        
        self.m_staticline13 = wx.StaticLine( self.m_panel20, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
        bSizer33.Add( self.m_staticline13, 0, wx.EXPAND |wx.ALL, 5 )
        
        bSizer38 = wx.BoxSizer( wx.HORIZONTAL )
        
        
        bSizer38.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )
        
        self.m_btnClose = wx.Button( self.m_panel20, wx.ID_ANY, u"关闭", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer38.Add( self.m_btnClose, 0, wx.ALL, 5 )
        
        bSizer33.Add( bSizer38, 0, wx.EXPAND, 5 )
        
        self.m_panel20.SetSizer( bSizer33 )
        self.m_panel20.Layout()
        bSizer33.Fit( self.m_panel20 )
        bSizer32.Add( self.m_panel20, 1, wx.EXPAND, 5 )
        
        self.SetSizer( bSizer32 )
        self.Layout()
        bSizer32.Fit( self )
        
        self.Centre( wx.BOTH )
        
        # Connect Events
        self.m_btnClampStretch.Bind( wx.EVT_BUTTON, self.OnClampStretch )
        self.m_btnClampShrink.Bind( wx.EVT_BUTTON, self.OnClampShrink )
        self.m_btnClampStop.Bind( wx.EVT_BUTTON, self.OnClampStop)
        self.m_btnSensorStretch.Bind( wx.EVT_BUTTON, self.OnSensorStretch )
        self.m_btnSensorShrink.Bind( wx.EVT_BUTTON, self.OnSensorShrink )
        self.m_btnSensorStop.Bind(wx.EVT_BUTTON, self.OnSensorStop)
        self.m_btnClose.Bind( wx.EVT_BUTTON, self.OnClose )
    
    
    # Virtual event handlers, overide them in your derived class
    def OnClampStretch( self, event ):
        if app.condomain.IsScram():
            wx.MessageBox(u'急停按钮被按下，如果要进行手动操作请松开急停按钮')
            return
        if app.condomain.IsAuto():
            wx.MessageBox(u'系统处于自动模式，如果要进行手动操作请将模式开关切换到手动模式')
            return
        RTC.AddTask(self.clampcylinder.Stretch, 0)

    
    def OnClampShrink( self, event ):
        if app.condomain.IsScram():
            wx.MessageBox(u'急停按钮被按下，如果要进行手动操作请松开急停按钮')
            return
        if app.condomain.IsAuto():
            wx.MessageBox(u'系统处于自动模式，如果要进行手动操作请将模式开关切换到手动模式')
            return
        RTC.AddTask(self.clampcylinder.Shrink, 0)
        
    def OnClampStop(self, event):
        if app.condomain.IsScram():
            wx.MessageBox(u'急停按钮被按下，如果要进行手动操作请松开急停按钮')
            return
        if app.condomain.IsAuto():
            wx.MessageBox(u'系统处于自动模式，如果要进行手动操作请将模式开关切换到手动模式')
            return
        self.clampcylinder.Stop()
    
    def OnSensorStretch( self, event ):
        if app.condomain.IsScram():
            wx.MessageBox(u'急停按钮被按下，如果要进行手动操作请松开急停按钮')
            return
        if app.condomain.IsAuto():
            wx.MessageBox(u'系统处于自动模式，如果要进行手动操作请将模式开关切换到手动模式')
            return
        RTC.AddTask(self.sensorcylinder.Stretch, 5)
    
    def OnSensorShrink( self, event ):
        if app.condomain.IsScram():
            wx.MessageBox(u'急停按钮被按下，如果要进行手动操作请松开急停按钮')
            return
        if app.condomain.IsAuto():
            wx.MessageBox(u'系统处于自动模式，如果要进行手动操作请将模式开关切换到手动模式')
            return
        RTC.AddTask(self.sensorcylinder.Shrink, 5)
        
    def OnSensorStop(self, event):
        if app.condomain.IsScram():
            wx.MessageBox(u'急停按钮被按下，如果要进行手动操作请松开急停按钮')
            return
        if app.condomain.IsAuto():
            wx.MessageBox(u'系统处于自动模式，如果要进行手动操作请将模式开关切换到手动模式')
            return
        self.sensorcylinder.Stop()
    
    def OnClose( self, event ):
        self.Close()
    